//
//  BaseTabBarController.m
//  oc1
//
//  Created by kokuma on 2017/2/12.
//  Copyright © 2017年 kokumams. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "BaseTabBarController.h"
#import "TopicController.h"
#import "VenueController.h"
#import "AcgGridController.h"
#import "UserController.h"
#import "BaseNavigationController.h"
#import "JFTabBar.h"
#import "UIColor+expanded.h"


@interface BaseTabBarController ()

@end

@implementation BaseTabBarController


- (void)viewDidLoad {
    [super viewDidLoad];
    JFTabBar* tabBar= [[JFTabBar alloc]initWithFrame:CGRectZero];
    [self setValue:tabBar forKey:@"tabBar"];
    [self prepareVc];
}

- (void)prepareVc{
    TopicController* newVc1 = [TopicController new];
    [self configChildViewController:newVc1 title:@"探索" imageName:@"tab_explore_n" selectedImageName:@"tab_explore_h"];
    VenueController* newVc2 = [VenueController new];
    [self configChildViewController:newVc2 title:@"分类" imageName:@"tab_classify_n" selectedImageName:@"tab_classify_h"];
    AcgGridController* newVc3 = [AcgGridController new];
    [self configChildViewController:newVc3 title:@"消息" imageName:@"tab_msg_n" selectedImageName:@"tab_msg_h"];
    UserController* newVc4 = [UserController new];
    [self configChildViewController:newVc4 title:@"我的" imageName:@"tab_mine_n" selectedImageName:@"tab_mine_h"];
    // 布局完立马选中，防止崩溃
    self.selectedIndex = 0;
}

- (void)configChildViewController:(UIViewController *)childViewController title :(NSString *)title imageName :(NSString *)imageName selectedImageName :(NSString *)selectedImageName
{
    childViewController.title = title;
    childViewController.tabBarItem.titlePositionAdjustment = UIOffsetMake(0, -3);
    
    [childViewController.tabBarItem setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:12]} forState: UIControlStateNormal];
    childViewController.tabBarItem.image=[[UIImage imageNamed:imageName]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    childViewController.tabBarItem.selectedImage = [[UIImage imageNamed:selectedImageName]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    UINavigationController*  navigationC = [[UINavigationController alloc]initWithRootViewController:childViewController];
    navigationC.title = title ;
    navigationC.navigationBar.backgroundColor = [UIColor blueColor];
    [self addChildViewController:navigationC];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (BOOL)shouldAutorotate{
    return false;
}

-(UIInterfaceOrientationMask)supportedInterfaceOrientations{
    return UIInterfaceOrientationMaskPortrait;
}

@end